//
//  ListDomainsDelegate.m
//  cTypica
//
//  Created by David Kavanagh on 3/24/09.
//  Copyright 2009 directThought. All rights reserved.
//

#import "ListDomainsDelegate.h"


@implementation ListDomainsDelegate
@synthesize listReceiver;

+ (id)delegateWithReceiver:(id<DomainListProtocol>)receiver {
	ListDomainsDelegate *ret = [self alloc];
	ret.listReceiver = receiver;
	return ret;
}

// XML parser delegate methods
- (void)parser: (NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
	if ([elementName isEqualToString:@"ListDomainsResult"]) {
		domains = [[NSMutableArray alloc] initWithCapacity:1];
	}
	else if ([elementName isEqualToString:@"ResonseMetadata"]) {
	}
}

- (void)parser: (NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
	NSString *cleanString = [currentStringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
	[currentStringValue setString:@""];
	if ([elementName isEqualToString:@"ListDomainsResult"]) {
		[listReceiver domainsReady:domains];
	}
	else if ([elementName isEqualToString:@"DomainName"]) {
		[domains addObject:cleanString];
	}
	else if ([elementName isEqualToString:@"NextToken"]) {
		nextToken = cleanString;
	}
	else if ([elementName isEqualToString:@"requestId"]) {
		requestId = cleanString;
	}
	else if ([elementName isEqualToString:@"BoxUsage"]) {
		boxUsage = cleanString;
	}
	
}
@end
